<template>
    <div class="checkProjectLibrary-increase">
        <!-- 新增弹窗 -->
        <a-modal
        class="checkProjectLibrary-increase-model"
         :visible="visibleShow" 
         :title="addEditParameter.id?'编辑':'新增'" 
         @ok="handleOk" 
         :confirmLoading="confirmLoading"
         :forceRender="true"
         :width="750"
         @cancel="visibleShow = false">
            <a-spin size="large" :spinning="spinning">
                <a-form v-if="visibleShow" :form="form"  @submit="handleSubmit" layout="inline">
                    <a-form-item label="审评查验类型">
                        <a-input
                        placeholder="请输入审评查验类型"
                        v-model:value="formState.ftype2"/>
                    </a-form-item>
                    <a-form-item label="附件类型">
                        <a-input
                        placeholder="请输入附件类型"
                        v-model:value="formState.ftype3"/>
                    </a-form-item>
                    <a-form-item label="类型4">
                        <a-input
                        placeholder="请输入类型4"
                        v-model:value="formState.ftype4"/>
                    </a-form-item>
                    <a-form-item label="章节">
                        <a-input
                        placeholder="请输入章节"
                        v-model:value="formState.ftype5"/>
                    </a-form-item>

                    <a-form-item label="类型6">
                        <a-input
                        placeholder="请输入类型6"
                        v-model:value="formState.ftype6"/>
                    </a-form-item>

                    <a-form-item label="条款">
                        <a-input
                        placeholder="请输入条款"
                        v-model:value="formState.ftype7"/>
                    </a-form-item>
                    <a-form-item label="类型8">
                        <a-input
                        placeholder="请输入类型8"
                        v-model:value="formState.ftype8"/>
                    </a-form-item>
                    <a-form-item label="内容">
                        <a-textarea v-model:value="formState.fcontent2" placeholder="请输入内容" :rows="4" />
                    </a-form-item>
                </a-form>
            </a-spin>
        </a-modal>
    </div>
</template>
<script>
import {typeInput, typeNumber, typeSelect, typeCheckbox, typeRadio} from '@/components/compSearchCriteria/ContractType'
import compSelector from '@/components/compSelector/compSelector'
import validator from '@/common/validator'
import {addServe, editServe,ocalityPostAction} from './service/index'
export default {
    components:{
        compSelector
    },
    props:{
        addEditParameter:{
            type:Object,
            default:[]
        }
    },
    data(){
        return{
            spinning:true,
            form: this.$form.createForm(this, { name: 'coordinated' }),
            visibleShow:false,
            confirmLoading:false,
            typeSelect:typeSelect,
            formState:{},
            rules:{
                ftype1: [{
                    required: true,
                    message: '请输入类型1',
                    trigger: 'blur',
                }],
                ftype2: [{
                    required: true,
                    message: '请输入类型2',
                    trigger: 'blur',
                }],
                ftype3: [{
                    required: true,
                    message: '请输入类型3',
                    trigger: 'blur',
                }],
                ftype4: [{
                    required: true,
                    message: '请输入类型4',
                    trigger: 'blur',
                }],
            },
            formRequer:'',
            optionsArr:[],
            submittedSuccessfully:false,
        }
    },
    watch:{
        addEditParameter(newval,oldVal){
            //console.log('给了什么啊',newval)
            this.formState = newval
            if(newval.id){
                this.formState.id = newval.id
            }
        }
    },
    mounted(){
        if(this.addEditParameter.id){
            this.formState.id = this.addEditParameter.id
        }
        
    },
    updated(){
        this.cancelLoading()
    },
    methods:{
        cancelLoading(){
            let timer = setInterval((val)=>{
                this.spinning = false
                clearInterval(timer);
            },500)
            
        },
        handleSubmit(e) {
            // e.preventDefault();
            var formState = {}
            this.form.validateFields((err, values) => {
                if (!err) {
                    this.confirmLoading = true
                    formState = {
                        ...this.formState,
                        ...values
                    }
                    if(formState.id){
                        editServe(formState).then(res=>{
                            if(res.code == 200){
                                this.submittedSuccessfully = true
                                this.$message.success('修改成功')
                                this.confirmLoading = false
                                this.visibleShow = false
                                this.$emit('handleOk',true,this.formState.id)
                            }else{
                                this.$message.warning(res.message)
                                this.confirmLoading = false
                            }
                        })
                    }else{
                        addServe(formState).then(res=>{
                            if(res.code == 200){
                                this.$message.success('添加成功')
                                
                                this.submittedSuccessfully = true
                                this.confirmLoading = false
                                this.visibleShow = false
                                this.$emit('handleOk',true,'')
                            }else{
                                this.$message.warning(res.message)
                                this.confirmLoading = false
                            }
                        })
                    }
                    
                }
            });
            
        },
        handleOk(){
            
            this.handleSubmit()
        }
    }

}

</script>
<style lang="less">
/* .ant-form-item-label{
    font-weight: 600;
} */
.checkProjectLibrary-increase{
    .ant-modal-title{
        font-weight: 600;
    }
    .ant-modal-header{
        background: rgb(222, 229, 237) !important;
    }
    .ant-upload-list{
        display: none !important;
    }
    .ant-modal-footer .ant-btn-primary{
        border: 1px solid #5ca3e5 !important;
        background-color: #5ca3e5 !important;
        color: #fff !important;
    }
    .ant-modal-content{
        width: 800px;
    }
    .ant-form{
        width: 100% !important;
    }
    .a-row-cox{
        display: flex;
        justify-content: space-around;
        margin-bottom: 25px;
    }
    
}
.checkProjectLibrary-increase-model{
    .ant-form-item{
        width: 100%;
    }
    .ant-form-item-label{
        width: 98px;
    }
    .ant-form-item-control-wrapp{
        width: 70%;
    }
}
</style>